<?php
if (!isset($modoBusqueda) || !$modoBusqueda){
    $contextMenu[0]["link"]      = "javascript:fn_nuevo()";
    $contextMenu[0]["linkIcon"]  = "application_add.png";
    $contextMenu[0]["linkTitle"] = "Nueva Factura";
}
?>
<script>
loadFunctionApFactura = function()
{
    fn_guardar = function ()
    {
    		var guardar = confirm("Desea guardar los datos?")
        if ( guardar ) 
        {
    		  var str=$("#form_editar").serialize();
    			$.ajax({
    				url:'/gourmet-express/trunk/src/index.php?do=PoFactura&accion=guardarSave',
    				data:str,
    				type:'get',
    				dataType: "json",
    				success:function (data){
    				        if(data.rpta=='true')
    				        {
    					        listarPoFactura();
    				        }else{
    				            alert(data.msg);
    				        }
    						}
    				   });
         }
    };
    
    fn_actualizar =function(){
    	var actualizar = confirm("Desea actualizar los datos?")
    	if ( actualizar ) {
      	var str=$("#form_editar").serialize();
      	$.ajax({
      		url:'/gourmet-express/trunk/src/index.php?do=PoFactura&accion=editarSave',
      		data:str,
      		type:'get',
      		dataType: "json",
      				success:function (data){
      				        if(data.rpta=='true')
      				        {
      					          listarPoFactura();
      				        }else{
      				            alert(data.msg);
      				        }
      						}
      				   });
    	}
     };
    
    fn_nuevo=function (){
    	$("#zonaContenedor").load("/gourmet-express/trunk/src/index.php?do=PoFactura&accion=nuevo", function(){
    	
    	});
    }; 
    
    		
    fn_editar=function (facId){			
    		   $("#zonaContenedor").load("/gourmet-express/trunk/src/index.php?do=PoFactura&accion=editar&facId="+facId, function(){
    		   	
    		   });
     }
    	
     fn_detalle = function fn_detalle(facId){			
    		   $("#zonaContenedor").load("/gourmet-express/trunk/src/index.php?do=PoFactura&accion=detalle&facId="+facId, function(){
    		   	
    		   });
     }
}
</script>
<body>
<div id="module">
    <?php include $_SERVER['DOCUMENT_ROOT'].'/gourmet-express/trunk/src/views/header.inc'; ?>
	<h3>:: Lista de Facturas </h3>
    <div id="moduleContent">

	<form id='formFact' name='formFact' method="post" >    
		Factura : <input type="text" name="num" size="15" value="">
		Proveedor : <input type="text" name="proveedorNombre" size="25" >  
          Status : <input type="text" name="status" size="5" >            
		<input type="submit" name="aceptar" value="aceptar" >    
	</form>         
		
		<table id="flex1" style="display:none"></table>
		<script type="text/javascript">
		$("#flex1").flexigrid({
			url: '/gourmet-express/trunk/src/index.php?do=PoFactura&accion=contenedor',
			dataType: 'json',
			colModel : [
				{display: 'Factura Id', name : 'facId', width : 100, sortable : true, align: 'left'},
				{display: 'Factura Nro', name : 'facNro', width : 100, sortable : true, align: 'left'},
				{display: 'Proveedor', name : 'proveedorName', width : 250, sortable : true, align: 'left'},
				{display: 'Estado', name : 'status', width : 60, sortable : true, align: 'left'},
				{display: '&nbsp;', name : 'opciones', width : 80, sortable : true, align: 'right'}
				],
			searchitems : [
				{display: 'Factura', name : 'facId'},
				{display: 'Estado', name : 'status', isdefault: true}
				],
			sortname: "facId",
			sortorder: "asc",
			usepager: true,
			title: 'Factura',
			useRp: true,
			rp: 15,
			showTableToggleBtn: true,
			width: 800,
			onSubmit: addFormData,
			height: 270
		});   
		
		
		//This function adds paramaters to the post of flexigrid. You can add a verification as well by return to false if you don't want flexigrid to submit			
		function addFormData(){
			//passing a form object to serializeArray will get the valid data from all the objects, but, if the you pass a non-form object, you have to specify the input elements that the data will come from
			var dt = $('#formFact').serializeArray();
			$("#flex1").flexOptions({params: dt});
			return true;
		}
			
		$('#formFact').submit(function (){
			$('#flex1').flexOptions({newp: 1}).flexReload();
			return false;
		});
		</script>
	</div>
	<div id="div_listar" align="center"></div>
	<div id="div_oculto" style="display: none;"></div>
</body>
<script>
loadFunctionApFactura();
</script>